from time import sleep

from selenium import webdriver

driver = webdriver.Firefox()
driver.get('https://www.baidu.com/')

sleep(3)

driver.find_element_by_partial_link_text('新闻').click()
sleep(3)


hds = driver.window_handles

print(hds)

print(len(hds))

print(driver.current_window_handle)


driver.switch_to.window(hds[1])
sleep(2)


driver.find_element_by_partial_link_text('军事').click()
driver.find_element_by_partial_link_text('部队进驻高原有什么讲究？对医疗补给要求很高，伤员后送十分困难').click()

driver.close()
sleep(2)


driver.switch_to.window(hds[0])
css_path = '#kw'
driver.find_element_by_css_selector(css_path).send_keys('Selenium')
driver.find_element_by_id("su").click()
sleep(3)

driver.quit()


